<?php
	function process()
	{
		global $output, $connection, $core;

		$output['exp'] = explode(" ", $output['text'], 2);
		if (strstr($output['exp'][0], $core['prefix']))
		{
			$output['command'] = strtolower($output['exp'][0]); //the command, ie: <prefix>say
			$output['data'] = $output['exp'][1]; //the data, ie: <text> from <prefix>say test
			$output['args'] = explode(" ", $output['data']);
			$output['cmd'] = str_replace($core['prefix'], "", $output['command']);
			
			//get's the arguments, and if there's an argument it changes the command so it doesn't have the argument in it
			if(strstr($output['command'], "."))
			{
				$output['argument'] = explode(".", $output['command']);
				$output['command'] = $output['argument'][0];
				$output['cmd'] = str_replace($core['prefix'], "", $output['command']);
				$output['argument'] = trim_array($output['argument']); //get rid of that trailing space
			}
		}		
		$data = $output['data'];
		$cmd = $output['cmd']; // command without the prefix
		
		switch($output['command'])
		{
			//admin command, sees if you're an admin
			case $core['prefix']."admin":
				$core['cmd']['admin'] = array('exec' => "msg", 'help' => "Usage: ".$core['prefix']."admin");
				if ($core['cmd']['admin']['module'] == null) { $core['cmd']['admin']['module'] = "loaded"; }

				if ($core['cmd']['admin']['module'] == "loaded")
				{
					if ($data != null)
					{
						if ($core['admin'][$data]['lvl'] != null) { $msg = $data." has level ".$core['admin'][$data]['lvl']." admin access to me."; }
						if ($core['admin'][$data]['lvl'] == null) { $msg = $data." doesn't have admin status"; }
					}
					if ($data == null)
					{
						$admin = $output['username'];
						if ($core['admin'][$admin]['lvl'] != null) { $msg = "You have level ".$core['admin'][$admin]['lvl']." admin access to me."; }
					}
				}
				elseif ($core['cmd']['admin']['module'] != "loaded")
				{
					$msg = "admin module not loaded";
				}
				break;
		
				
			//nick command
			case $core['prefix']."nick":
				$core['cmd']['nick'] = array('exec' => "raw", 'help' => "Usage: ".$core['prefix']."nick <new nick>", 'admin' => "10");
				if ($core['cmd']['nick']['module'] == null) { $core['cmd']['nick']['module'] = "loaded"; }
				$newnick = $output['args'][1];

				if ($core['cmd']['nick']['module'] == "loaded")
				{
					if ($newnick == $core['nick'])
					{
						$msg[] = "NICK :". $output['args'][1];
						$msg[] = "PRIVMSG NickServ IDENTIFY ". $core['nspass'];
					}
					
					else
					{
						$msg[] = "NICK :". $output['args'][1];
					}
				}

				elseif ($core['cmd']['nick']['module'] == "unloaded")
				{
					$msg = "admin module not loaded";
				}
				break;

			//join command
			case $core['prefix']."join":
				$core['cmd']['join'] = array('exec' => "raw", 'help' => "Usage: ".$core['prefix']."join <channel>", 'admin' => "10");
				if ($core['cmd']['join']['module'] == null) { $core['cmd']['join']['module'] = "loaded"; }

				if ($core['cmd']['join']['module'] == "loaded")
				{
					$msg = "JOIN :".$data;
				}
				elseif ($core['cmd']['join']['module'] == "unloaded")
				{
					$msg = "join module not loaded";
				}
				break;

			//part command
			case $core['prefix']."part":
				$core['cmd']['join'] = array('exec' => "raw", 'help' => "Usage: ".$core['prefix']."part <channel>", 'admin' => "10");
				if ($core['cmd']['part']['module'] == null) { $core['cmd']['part']['module'] = "loaded"; }

				if ($core['cmd']['part']['module'] == "loaded")
				{
					if ($data != null)
					{
						$msg = "PART :".$data;
					}

					else
					{
						$msg = "PART :".$output['channel'];
					}
				}
				elseif ($core['cmd']['part']['module'] == "unloaded")
				{
					$msg = "part module not loaded";
				}
				break;

			//say command
			case $core['prefix']."say":
				$core['cmd']['say'] = array('exec' => "msg", 'help' => "Usage: ".$core['prefix']."say <text>", 'admin' => "10");
				if ($core['cmd']['say']['module'] == null) { $core['cmd']['say']['module'] = "loaded"; }
				
				if ($core['cmd']['say']['module'] == "loaded")
				{
					$msg = $data;
				}
				elseif ($core['cmd']['say']['module'] == "unloaded")
				{
					$msg = "say module not loaded";
				}
				break;

			//eval command
			case $core['prefix']."eval":
				$core['cmd']['eval'] = array('exec' => "msg", 'help' => "Usage: ".$core['prefix']."eval <php>", 'admin' => "20");
				if ($core['cmd']['eval']['module'] == null) { $core['cmd']['eval']['module'] = "loaded"; }
				
				if ($core['cmd']['eval']['module'] == "loaded")
				{
					eval($data);
				}
				elseif ($core['cmd']['eval']['module'] == "unloaded")
				{
					$msg = "eval module not loaded";
				}
				break;

			//makes temp admins
			case $core['prefix']."mkadmin":
				$core['cmd']['mkadmin'] = array('exec' => "msg", 'help' => "Usage: ".$core['prefix']."mkadmin <nick> <lvl>", 'admin' => "20");
				if ($core['cmd']['mkadmin']['module'] == null) { $core['cmd']['mkadmin']['module'] = "loaded"; }
				
				if ($core['cmd']['mkadmin']['module'] == "loaded")
				{
					$adminick = $output['args'][0];
					$adminlvl = $output['args'][1];
					raw("WHOIS :".$output['args'][0]);
					$i == 0;

					while($i != 2) 
					{
						$whois[] = trim(fgets($connection, 70));
						$i++;
						if ($i == 2) {
							break;
						}
					}
					$whois = explode(" ", $whois[0]);
					$adminhost = $whois[5];
					
					$core['admin'][$adminick]['host'] = $adminhost;
					$core['admin'][$adminick]['lvl'] = $adminlvl;
					pm($adminick, "You now have level ".$adminlvl." to me.");
				}

				elseif ($core['cmd']['mkadmin']['module'] == "unloaded")
				{
					$msg = "mkadmin module not loaded";
				}
				break;
				
			//removes temp admins
			case $core['prefix']."rmadmin":
				$core['cmd']['rmadmin'] = array('exec' => "msg", 'help' => "Usage: ".$core['prefix']."rmadmin <nick>", 'admin' => "20");
				if ($core['cmd']['rmadmin']['module'] == null) { $core['cmd']['rmadmin']['module'] = "loaded"; }
				
				if ($core['cmd']['rmadmin']['module'] == "loaded")
				{
					$adminick = $output['args'][0];
					unset($core['admin'][$adminick]);
					pm($adminick, "Your administrative privledges have been revoked.");
				}
				
				elseif ($core['cmd']['rmadmin']['module'] == "unloaded")
				{
					$msg = "rmadmin module not loaded";
				}
				break;

			//die command
			case $core['prefix']."die":
				$core['cmd']['die'] = array('exec' => "bdie", 'help' => "Usage: ".$core['prefix']."die <text (optional)>", 'admin' => "20");
				if ($core['cmd']['die']['module'] == null) { $core['cmd']['die']['module'] = "loaded"; }
				
				if ($core['cmd']['die']['module'] == "loaded")
				{
					if ($output['argument'] != "help")
					{
						if($data != null)
						{
							$msg = $data;
						}

						else
						{
							$msg = "sie hatred";
						}
					}
				}
				
				elseif ($core['cmd']['eval']['module'] == "unloaded")
				{
					$msg = "die module not loaded";
				}
				break;
		}
	
		//arguments, modify $msg to do cool stuff.
		if (is_array($output['argument']))
		{
			foreach ($output['argument'] as $output['argument'])
			{
				if ($output['argument'] == "lower") { $msg = strtolower($msg); }
				if ($output['argument'] == "upper") { $msg = strtoupper($msg); }
				if ($output['argument'] == "rev") { $msg = strrev($msg); }
				if ($output['argument'] == "len") { $msg = strlen($msg); }
				if ($output['argument'] == "md5") { $msg = md5($msg); }
				if ($output['argument'] == "sha1") { $msg = sha1($msg); }
				if ($output['argument'] == "crypt") { $msg = crypt($msg); }
				if ($output['argument'] == "var")
				{
					$core['var'][$cmd] = $msg;
					$msg = $msg;
				}
				if ($output['argument'] == "help")
				{
					$msg = $core['cmd'][$cmd]['help'];
					if (($admin == true) || (!isset($admin))) { $msg .= ", You have access to this command"; }
					if (($admin == false) && (isset($admin))) { $msg .= ", You don't have access to this command"; }
				}
				if (($output['command'] == $core['prefix']."".$core['nick']) && ($output['argument'] == "ident"))
				{
					pm("NICKSERV", "identify ".$core['nspass']);
				}
				if (($output['command'] == $core['prefix']."".$core['nick']) && ($output['argument'] == "uptime"))
				{
					$now = strtotime("now");
					$uptime = $now - $core['starttime'];
					$uptime = uptary($uptime);
					$msg = "I've been up for";
					if (isset($uptime['years'])) { $msg .= " ".$uptime['years']. " years"; }
					if (isset($uptime['weeks'])) { $msg .= " ".$uptime['weeks']. " weeks"; }
					if (isset($uptime['days'])) { $msg .= " ".$uptime['days']. " days"; }
					if (isset($uptime['minutes'])) { $msg .= " ".$uptime['minutes']. " minutes"; }
					if (isset($uptime['seconds'])) { $msg .= " ".$uptime['seconds']. " seconds"; }
				}
			}
		}
		if ($msg != null)
		{
			if(($core[$cmd]['admin'] == null) || (admin($core['cmd'][$cmd]['admin'])))
			{
				$core['cmd'][$cmd]['exec']($msg);
			}
			else
			{
				msg("You don't have admin status");
			}
		}
		if ($core['debug'] == true)
		{
			var_dump($output);
			var_dump($core);
			var_dump($msg);
		}
	}
?>